
<?php
	include("database.php");
	require_once ("fb.php");
	require_once ("FirePHP.class.php");

	session_start();
	$estacioni = $_SESSION['nombre_estacion'];

	$dir= "../files/".$estacioni."/";
	$dir_thumbs = "../files/".$estacioni."/";
	$images = array();
	$d = dir($dir_thumbs);

	ini_set('memory_limit', '-1');

	//fb($dir_thumbs,"");
	
	while($name = $d->read()){
		$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
		//fb($dir_thumbs.$name,"");
		
		if($name == '.' or $name == '..') continue;
		
		if (($ext == 'pdf') || 
			($ext == 'doc') || 
			($ext == 'docx') || 
			($ext == 'xls') || 
			($ext == 'xlsx' ))
		{
			$size = filesize($dir_thumbs.$name);
			$lastmod = filemtime($dir_thumbs.$name)*1000;
			$images[] = array('name'=>utf8_encode($name), 'size'=>$size,'lastmod'=>$lastmod, 'url'=>utf8_encode($dir_thumbs.$name));
		}
	}
	$d->close();
	$o = array('images'=>$images);
	echo json_encode($o);

//Falta borrar si es una nueva sesion!!!
/*
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) 
{
  // open the directory
  $dir = opendir( $pathToImages );

  // loop through it, looking for any/all JPG files:
  while (false !== ($fname = readdir( $dir ))) {
	//Si no existe el thumbnail, no creo.
	
	if (!file_exists($pathToThumbs.$fname))
	{
		// parse path for the extension
		$info = pathinfo($pathToImages.$fname);
		// continue only if this is a JPEG image
		if ( strtolower($info['extension']) == 'jpg' or
			 strtolower($info['extension']) == 'gif' or
			 strtolower($info['extension']) == 'bmp') 
		{
		  //echo "Creating thumbnail for {$fname} <br />";
		  fb($pathToImages.$fname,"");
		  // load image and get image size
		  $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
		  $width = imagesx( $img );
		  $height = imagesy( $img );

		  // calculate thumbnail size
		  $new_width = $thumbWidth;
		  $new_height = floor( $height * ( $thumbWidth / $width ) );

		  // create a new tempopary image
		  $tmp_img = imagecreatetruecolor( $new_width, $new_height );

		  // copy and resize old image into new image 
		  imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

		  // save thumbnail into a file
		  imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
		}
		else if (strtolower($info['extension']) == 'png')
		{
			$img = imagecreatefrompng( "{$pathToImages}{$fname}" );
			$width = imagesx( $img );
			$height = imagesy( $img );

			// calculate thumbnail size
			$new_width = $thumbWidth;
			$new_height = floor( $height * ( $thumbWidth / $width ) );

			// create a new tempopary image
			$tmp_img = imagecreatetruecolor( $new_width, $new_height );

			// copy and resize old image into new image 
			imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

			// save thumbnail into a file
			imagepng( $tmp_img, "{$pathToThumbs}{$fname}" );
		}
    }
  }
  // close the directory
  closedir( $dir );
}

//createThumbs($dir,$dir_thumbs,100);

		*/
?>
